<template>
  <!-- 重点文章 配置 -->
  <h-modal v-model="show" :title="modalForm.title" @submit="submit" >
    <a-form-model ref="ruleForm" :model="form" :rules="rules" size="large">
      <a-row :gutter="100">
        <!-- <a-col :span="12">
          <a-form-model-item label="事件可控程度" prop="controllableDegree">
            <a-radio-group v-model="form.controllableDegree">
              <a-radio-button :value="0">可控</a-radio-button>
              <a-radio-button :value="1">失控</a-radio-button>
            </a-radio-group>
          </a-form-model-item>
        </a-col> -->
        <a-col :span="12">
          <a-form-model-item label="研判人" prop="judge">
            <a-input v-model="form.judge"></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="24">
          <a-form-model-item label="研判内容" prop="content">
            <a-textarea :rows="5" size="large" v-model="form.content" placeholder="请输入研判内容"></a-textarea>
          </a-form-model-item>
        </a-col>
      </a-row>

    </a-form-model>
  </h-modal>
</template>

<script>
import moment from 'moment';
import { addJudge } from '@/api/serve';
import cloneDeep from 'lodash/cloneDeep';

export default {
  props: {
    showModal: {
      type: Boolean,
      default: false
    },
    formData: {
      type: Object,
      default: () => {}
    }
  },
  model: {
    prop: 'showModal',
    event: 'update:showModal'
  },
  watch: {
    showModal: {
      handler(val) {
        this.show = val;
        if (val) {
          this.modalForm = this.formData;
          this.form.eventId = this.formData.id;
        }
      },
      immediate: true
    },
    show(val) {
      this.$emit('update:showModal', val);
    }
  },
  data() {
    return {
      moment,
      modalForm: '',
      show: false,
      form: {
        controllableDegree: 0
      },
      rules: {
        controllableDegree: [{ required: true, message: '请选择' }],
        judge: [{ required: true, message: '请输入' }],
        content: [{ required: true, message: '请输入' }]
      }
    };
  },
  methods: {
    submit() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          addJudge(this.form).then(res => {
            this.$message.success('创建成功');
            this.show = false;
            this.$emit('submit', cloneDeep(this.form));
            this.form = cloneDeep({
              controllableDegree: 0
            });
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  }
};
</script>

<style>

</style>
